<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>有序数组的平方</title>
</head>

<body>
  <script>
    function fn(nums) {
      let res = nums.map(item => {
        return item * item
      }).sort((a, b) => {
        return a - b
      })
      return res
    };
    console.log(fn([-4, -1, 0, 3, 10]))
  </script>
</body>

</html>